import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";

@Injectable()
export class FavoriteListProvider {

    constructor(public http: HttpClient) {

    }

    getFavoriteList(): Observable<any> {
        return this.http.get('/favorite/v1/favorites?not-loading=0');
    }

    addToFavorites(clientId, userType): Observable<any> {
        return this.http.post('/favorite/v1/favorite?not-loading=0', [{
            "userId": clientId,
            "userType": userType
        }], {responseType: 'text'});
    }

    removeFromFavorite(clientId): Observable<any> {
        return this.http.delete(`/favorite/v1/favorite/${clientId}?not-loading=0`, {responseType: 'text'});
    }

    deleteFavorite(favoriteId: string) {
        let data: string[] = [];
        data.push(favoriteId);
        return this.http.post('/favorite/v1/favorites?not-loading=0', data, {responseType: 'text'});
    }

}
